package com.shycloud.mido.homework.sharding;

import java.util.Collection;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import lombok.extern.slf4j.Slf4j;

/**
 * @author Xiaoxing Yu
 * @date 2020/11/18 下午2:24
 **/
@Slf4j
public class HomeworkMainPreciseShardingAlgorithm implements PreciseShardingAlgorithm<Integer> {

	private final static String tablePrefix = "mido_homework_main";

	@Override
	public String doSharding(Collection<String> collection, PreciseShardingValue<Integer> shardingValue) {
		log.info("执行了between算法" + shardingValue.getValue());

		Integer value = shardingValue.getValue();

		Integer tableIndex = ConsistentHashSharding.getConsistentHash(value) % 3;

//		return tablePrefix + new BigDecimal(value).divideAndRemainder(new BigDecimal(3))[1].toString();
		return tablePrefix + tableIndex;
	}
}
